/**
 * @BaseMediator.as
 * 
 * @author sodaChen mail:asframe@163.com
 * @version 1.0
 * <br>Copyright (C), 2012 ASFrame.com
 * <br>This program is protected by copyright laws.
 * <br>Program Name:ASFrame AStruts2
 * <br>Date:2012-4-8
 */
package com.asframe.astruts2.mvc.mediator
{
	import com.asframe.astruts2.context.IAStrutsContext;
	import com.asframe.astruts2.context.IContextAware;
	import com.asframe.astruts2.interfaces.IView;
	import com.asframe.astruts2.mvc.controller.BaseAdapter;
	
	import flash.display.Sprite;
	
	/**
	 * 基础的中介对象，没有做任何实现，相当于一个适配器
	 * @author sodaChen
	 * @Date:2012-4-8
	 */
	public class MediatorAdapter extends BaseAdapter implements IMediator,IContextAware
	{
		protected var view				:*;
		protected var context			:IAStrutsContext
		/** 单个页面的显示容器 **/
		protected var viewContainer		:Sprite;
		/** 所有页面的容器 **/
		private var containers			:Sprite;
		
		public function setView(view:*):void
		{
			this.view = view;
			if(view is IView)
			{
				viewContainer = IView(view).getContainer();
			}
			else
			{
				viewContainer = Sprite(view);
			}
		}
		public function setContext(context:IAStrutsContext):void
		{
			this.context = context;
			containers = context.getRootContainer().getViewContainer();
		}
		
		public function getNotices():Array
		{
			return [];
		}
		public function addView():void
		{
			viewContainer.visible = true;
			if(viewContainer.parent == null)
			{
				containers.addChild(viewContainer);
			}
		}
		
		public function removeView():void
		{
			if(viewContainer.parent != null)
			{
				 containers.removeChild(viewContainer);
			}
		}
	}
}
